package com.returnsoft.resource.validator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator("validateUsername")
public class ValidateUsername implements Validator {

	@Override
	public void validate(FacesContext context, UIComponent component,
			Object value) throws ValidatorException {
		String username = value.toString();
		
		if (username.trim().length()==0) {
			
			FacesMessage msg =
		              new FacesMessage("El usuario es nulo.",
		              "Debe ingresar usuario.");
		      msg.setSeverity(FacesMessage.SEVERITY_WARN);
		      throw new ValidatorException(msg);
		      
		}
		
	}

}
